export function setArrayValue (data, val) {
    for (let item of data) {
        item[val.index] = val.val1
        if (item[val.childName] && item[val.childName].length) {
            setArrayValue(item[val.childName], val)
        }
      }
}
export function setAdd (self, data, val) {
    for (let item of data) {
        self.$set(item,val.index, val.val1)
        if (item[val.childName] && item[val.childName].length) {
            setAdd(self,item[val.childName], val)
        }
      }
}
/* 已选商品列表*/
export function getValueArray (data, val) {
    /*
            1、如果父级的checked为false,就把父级删掉
            2、如果子集的checked为false，就删掉
    */
   for (let key in data) {
       if( data[key][val.index] == val.status ) {
            data[key] = ''
       } 
       if (data[key][val.childName] && data[key][val.childName].length) {
            getValueArray(data[key][val.childName], val)
       }
   }
} 
// 
export function setEmptyArray (data, val) {
    for(var i = 0;i<data.length;i++){
        if (data[i]==''||data[i]==null||typeof(data[i])==undefined) {
            data.splice(i,1);
            i=i-1;
        }
        if(data[i]) {
            if (data[i][val.childName] && data[i][val.childName].length) {
                setEmptyArray(data[i][val.childName], val)
            }
        }
    }
}
export function getSelectStatus (data, val) {
    let status = true;
    for (let item of data) {
        if (!item[val.index]) {
            status = false;
        }
        if (item[val.childName] && item[val.childName].length) {
           return  getSelectStatus (item[val.childName], val)
        }
    }
    return status;
}

export function deleteValueArray (data, val) {
    for (let key in data) {
        let status = true;
        
        if (data[key][val.childName] && data[key][val.index]) {
            for (let todo in data[key][val.childName]) {
                if(data[key][val.childName][todo][val.index]) {
                    data[key][val.childName][todo] = ''
                }else{
                    status = false
                }
            }
        }
        if(!data[key][val.index]){
            status = false
        }
        if(status) {
            data[key] = ''
        }
    }
}
export function getValueStatus (data, val) {
    for (let key in data) {
        let status = true;
        if (data[key][val.childName] && data[key][val.index]) {
            for (let todo in data[key][val.childName]) {
                if(!data[key][val.childName][todo][val.index]) {
                    // data[key][val.childName][todo] = ''
                }else{
                    status = false
                }
            }
        }
        if(status) {
            data[key][val.index] = false
        }
    }
}
export const columns1= [
    {
        title: '商品编码',
        key: 'code'
    },{
        title: 'SKU编码',
        key: 'skuCode'
    },{
        title: '商品',
        key: 'name'
    },{
        title: '零售价',
        key: 'price'
    },{
        title: '状态',
        key: 'discount'
    },{
        title: '库存',
        key: 'sale'
    },{
        title: '操作',
        key: 'set'
    }
]

export const data1 = [{
    id: 1,
    code: '1292711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 100.154,
    img: "",
    discount: 10.00,
    sale: 15.12,
    skuCode: '-',
    checked: false,
    showChildren: false,
    children: [{
    code: '-',
    skuCode: '4492711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 651.00,
    discount: '',
    sale: 25.00,
    checked: false
    }, {
    code: '-',
    skuCode: '4492711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 9154.15,
    discount: '',
    sale: '',
    checked: false
    }]
}, {
    id: 2,
    code: '12927114531',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 100.154,
    img: "",
    discount: '',
    skuCode: '-',
    sale: '',
    showChildren: false,
    checked: false
}, {
    id: 3,
    code: '1292711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 100.154,
    img: "",
    discount: '',
    sale: '',
    skuCode: '-',
    checked: false,
    showChildren: false,
    children: [{
    code: '-',
    skuCode: '4492711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 651.00,
    discount: '',
    sale: '',
    checked: false
    }, {
    code: '-',
    skuCode: '4492711453',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 9154.15,
    discount: '',
    sale: '',
    checked: false
    }]
}, {
    id: 4,
    code: '12927114531',
    name: '朝阳轮胎 泥地越野皮卡车胎 SL366系列',
    price: 100.154,
    img: "",
    discount: '',
    skuCode: '-',
    sale: '',
    showChildren: false,
    checked: false
}] 